package com.android.fluttercontainer;

import android.util.Log;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.SPUtils;

import java.util.Map;

import javax.security.auth.login.LoginException;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;


/**
 * 创建者 ：  huyangyang962
 * 创建日期： 2021/5/24 6:39 PM
 * 描述：
 */
public class MyMethodCall implements MethodChannel.MethodCallHandler {
    //需要和flutter 保持一致
    public static final String METHOD_CHANNEL_KEY = "gapsk-acp";

    public static final String JUMP_PAGE_NAME_KEY = "pageName";

    public static final String JUMP_PAGE_METHOD_KEY = "goToPage";

    @Override
    public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {

        String methodName = call.method;
        // TODO log 调式
        Log.i("onMethodCall", "onMethodCall:==>" + methodName);
        switch (methodName) {
            case JUMP_PAGE_METHOD_KEY:
                Map<String, Object> params = (Map<String, Object>) call.arguments;
                if (params != null && params.get(JUMP_PAGE_NAME_KEY) != null) {
                    String pageName = (String) params.get(JUMP_PAGE_NAME_KEY);
                    //TODO log 调式
                    Log.i("MyMethodCall", "onMethodCall=pageName==>" + pageName);
                    SchmelUtils.goToActivity(FlutterApplication.sApplication, pageName, params);
                }
                result.success(true);
                break;
            case "saveJwt":
                String jwt = (String) call.arguments;
                //TODO log 调式
                Log.i("MyMethodCall", "saveJwt===>" + jwt);
                SPUtils.getInstance("GAPSK_AI_QM").put("jwt", jwt);
                result.success(true);
                break;
            case "getJwt":
                String jwtLocal = SPUtils.getInstance("GAPSK_AI_QM").getString("jwt", "");
                //TODO log 调式
                Log.i("MyMethodCall", "getJwt===>" + jwtLocal);
                result.success(jwtLocal);
                break;
            case "clearJwt":
                SPUtils.getInstance("GAPSK_AI_QM").remove("jwt");
                result.success(true);
                break;
        }
    }
}
